﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:conv="clr-namespace:BaseTypesControlLib.Converters"
                    xmlns:controls="clr-namespace:BaseTypesControlLib.Controls"
                    >
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="/BaseTypesControlLib;component/Themes/CustomListStyles.xaml"/>
    </ResourceDictionary.MergedDictionaries>
    
    <conv:GaugeLabelConverter x:Key="lblConv"/>
    <conv:GaugeProgressConverter x:Key="valConv"/>
    <conv:BitmapMarginConverter x:Key="marginConv"/>
    <conv:BitmapPathConverter x:Key="pathConv"/>

    <Style TargetType="{x:Type controls:CustomListFieldControl}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type controls:CustomListFieldControl}">
                    <Border Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            >
                        <ItemsControl ItemsSource="{Binding Path=Items, RelativeSource={RelativeSource Mode=TemplatedParent}}">
                        </ItemsControl>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    
    <Style TargetType="{x:Type controls:SeparatorFieldControl}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type controls:SeparatorFieldControl}">
                    <Border Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            >
                        <Rectangle x:Name="rect" Fill="Black" StrokeThickness="0"
                                   SnapsToDevicePixels="True" Stroke="Transparent"
                                   HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsHorizontal" Value="True">
                            <Setter Property="Margin" Value="0,1,0,1" TargetName="rect"/>
                        </Trigger>
                        <Trigger Property="IsHorizontal" Value="False">
                            <Setter Property="Margin" Value="1,0,1,0" TargetName="rect"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    <Style TargetType="{x:Type controls:LabelFieldControl}">
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type controls:LabelFieldControl}">
                    <Border Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            >
                        <TextBlock Text="{TemplateBinding Text}" TextWrapping="Wrap" />
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    <Style TargetType="{x:Type controls:EditFieldControl}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type controls:EditFieldControl}">
                    <Border Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            >
                        <TextBlock Text="{TemplateBinding DisplayText}"
                               TextWrapping="Wrap" />
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    <Style TargetType="{x:Type controls:BitmapFieldControl}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type controls:BitmapFieldControl}">
                    <Border Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}" >
                        <Image Stretch="None" Source="{Binding Path=Bitmap, RelativeSource={RelativeSource Mode=TemplatedParent}, Converter={StaticResource pathConv}}" >
                            <Image.Margin>
                                <MultiBinding Converter="{StaticResource marginConv}">
                                    <Binding Path="HorizontalSpace" RelativeSource="{RelativeSource Mode=TemplatedParent}"/>
                                    <Binding Path="VerticalSpace" RelativeSource="{RelativeSource Mode=TemplatedParent}"/>
                                </MultiBinding>
                            </Image.Margin>
                        </Image>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    <Style TargetType="{x:Type controls:ButtonFieldControl}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type controls:ButtonFieldControl}">
                    <Border x:Name="bgBorder" CornerRadius="3" Margin="2"
                                BorderThickness="2" BorderBrush="#ffffff" >
                        <Border.Background>
                            <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                                <GradientStop Offset="0" Color="#398aff" />
                                <GradientStop Offset="1" Color="#0859d6" />
                            </LinearGradientBrush>
                        </Border.Background>
                        <Border x:Name="textBorder"
                                    Background="{TemplateBinding Background}"
                                    BorderBrush="{TemplateBinding BorderBrush}"
                                    BorderThickness="{TemplateBinding BorderThickness}"
                                    HorizontalAlignment="Center" VerticalAlignment="Center"
                                    Margin="10,5" >
                            <TextBlock Text="{TemplateBinding Label}" Foreground="White"
                               TextWrapping="WrapWithOverflow" x:Name="text" />
                        </Border>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="Editable" Value="False">
                            <Setter TargetName="text" Property="Foreground" Value="LightGray" />
                            <Setter TargetName="textBorder" Property="Background" Value="Transparent" />
                        </Trigger>
                        <Trigger Property="ReadOnly" Value="True">
                            <Setter TargetName="text" Property="Foreground" Value="LightGray" />
                            <Setter TargetName="textBorder" Property="Background" Value="Transparent" />
                        </Trigger>
                        <Trigger Property="Focusable" Value="False">
                            <Setter TargetName="bgBorder" Property="Background" >
                                <Setter.Value>
                                    <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                                        <GradientStop Offset="0" Color="#848284" />
                                        <GradientStop Offset="1" Color="#5a5d5a" />
                                    </LinearGradientBrush>
                                </Setter.Value>
                            </Setter>
                            <Setter TargetName="text" Property="Foreground" Value="White" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    <Style TargetType="{x:Type controls:CheckBoxFieldControl}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type controls:CheckBoxFieldControl}">
                    <Border Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            >
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition />
                            </Grid.ColumnDefinitions>

                            <Grid Width="{TemplateBinding FontSize}" Height="{TemplateBinding FontSize}"
                                  HorizontalAlignment="Center" VerticalAlignment="Center"
                                  >
                                <Border x:Name="rect" Background="SteelBlue" 
                                           BorderBrush="White" BorderThickness="1"
                                        CornerRadius="3" Margin="1"/>
                                <Path Margin="5" Stretch="Uniform" Stroke="White"
                                      x:Name="path" StrokeThickness="2"
                                      Data="M 1,5 L5,9 L9,1" Visibility="Hidden"
                                      />
                            </Grid>
                            <TextBlock x:Name="text" Text="{TemplateBinding Label}" Grid.Column="1"/>
                        </Grid>
                        
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="Checked" Value="True">
                            <Setter Property="Visibility" Value="Visible" TargetName="path"/>
                        </Trigger>
                        <Trigger Property="ReadOnly" Value="True">
                            <Setter Property="Background" Value="LightGray" TargetName="rect"/>
                            <Setter Property="Foreground" Value="LightGray" TargetName="text"/>
                        </Trigger>
                        <Trigger Property="Editable" Value="False">
                            <Setter Property="Background" Value="LightGray" TargetName="rect"/>
                            <Setter Property="Foreground" Value="LightGray" TargetName="text"/>
                        </Trigger>
                        <Trigger Property="Focusable" Value="False">
                            <Setter Property="Background" Value="#444444" TargetName="rect"/>
                            <Setter Property="Foreground" Value="Black" TargetName="text"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    <Style TargetType="{x:Type controls:RadioFieldControl}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type controls:RadioFieldControl}">
                    <Border Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            >
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition />
                            </Grid.ColumnDefinitions>
                            <Grid Width="{TemplateBinding FontSize}" Height="{TemplateBinding FontSize}"
                                  HorizontalAlignment="Center" VerticalAlignment="Center"
                                  >
                                <Ellipse x:Name="ellipse" Fill="SteelBlue" 
                                         Stroke="White" StrokeThickness="1"
                                         Margin="1"/>
                                <Ellipse Margin="6" Fill="White"
                                      x:Name="path" Visibility="Hidden"
                                      />
                            </Grid>
                            <TextBlock x:Name="text" Text="{TemplateBinding Label}" Grid.Column="1"/>
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="Checked" Value="True">
                            <Setter Property="Visibility" Value="Visible" TargetName="path"/>
                        </Trigger>
                        <Trigger Property="ReadOnly" Value="True">
                            <Setter Property="Fill" Value="LightGray" TargetName="ellipse"/>
                            <Setter Property="Foreground" Value="LightGray" TargetName="text"/>
                        </Trigger>
                        <Trigger Property="Editable" Value="False">
                            <Setter Property="Fill" Value="LightGray" TargetName="ellipse"/>
                            <Setter Property="Foreground" Value="LightGray" TargetName="text"/>
                        </Trigger>
                        <Trigger Property="Focusable" Value="False">
                            <Setter Property="Fill" Value="#444444" TargetName="ellipse"/>
                            <Setter Property="Foreground" Value="Black" TargetName="text"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    <Style TargetType="{x:Type controls:GaugeFieldControl}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type controls:GaugeFieldControl}">
                    <Border Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            >
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>
                            <TextBlock VerticalAlignment="Center" >
                    <TextBlock.Text>
                        <MultiBinding Converter="{StaticResource lblConv}">
                            <Binding Path="Label" RelativeSource="{RelativeSource Mode=TemplatedParent}" />
                            <Binding Path="LabelAsProgress" RelativeSource="{RelativeSource Mode=TemplatedParent}"/>
                        </MultiBinding>
                    </TextBlock.Text>
                            </TextBlock>
                            <Grid Grid.Column="1">
                                <Border Name="PART_Track" CornerRadius="0" 
            Background="White" BorderBrush="White" BorderThickness="1" />
                                <Border Name="PART_Indicator" CornerRadius="0" Background="Blue" 
            BorderBrush="Blue" BorderThickness="1" HorizontalAlignment="Left" />
                            </Grid>

                            <TextBlock Grid.Column="1" HorizontalAlignment="Center"
                           VerticalAlignment="Center" Margin="0,5">
                    <TextBlock.Text>
                        <MultiBinding Converter="{StaticResource valConv}">
                            <Binding Path="Label" RelativeSource="{RelativeSource Mode=TemplatedParent}"/>
                            <Binding Path="Value" RelativeSource="{RelativeSource Mode=TemplatedParent}"/>
                            <Binding Path="PercentValue" RelativeSource="{RelativeSource Mode=TemplatedParent}"/>
                            <Binding Path="LabelAsProgress" RelativeSource="{RelativeSource Mode=TemplatedParent}"/>
                            <Binding Path="NoText" RelativeSource="{RelativeSource Mode=TemplatedParent}"/>
                            <Binding Path="Percent" RelativeSource="{RelativeSource Mode=TemplatedParent}"/>
                        </MultiBinding>
                    </TextBlock.Text>
                            </TextBlock>
                        </Grid>
                    </Border>
                    
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>
